package com.admin.controller;

import com.admin.eneity.R;
import com.admin.eneity.SysUser;
import com.admin.service.SysUserService;
import com.admin.util.JwtUtils;
import com.admin.util.RsaUtils;
import com.admin.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 吴驰明
 * @date 2023/7/13
 * @Description  测试
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private SysUserService sysUserService;


    @RequestMapping("/user/list")
    public R userList(@RequestHeader(required = false) String token){
        if (StringUtil.isNotEmpty(token)){
            Map<String,Object> resultMap=new HashMap<>();
            List<SysUser> userList=sysUserService.list();
            resultMap.put("userList",userList);
            return R.ok(resultMap);
        }else {
            return R.error(401,"没有权限");
        }
    }

    @GetMapping("/login")
    public R login(@RequestParam("text") String text){
////        String token = JwtUtils.genJwtToken("java1234");
//        return R.ok().put("token",token);
        return R.ok().put("text",RsaUtils.decrypt(text));
    }


}
